package com.sxz.sbs.module.client.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.client.bean.ContractTypeBean;
import com.sxz.sbs.module.client.view.DealEvidenceView;
import com.sxz.sbs.module.sale.mode.ImgBackBean;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;

/**
 * 上传凭证 P
 */

public class DealEvidencePresenter extends RxPresenter<DealEvidenceView>{
    /**
     * 上传定金合同
     * @param map
     */
    public void uploadEvidence (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().uploadEvidence(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onUploadEvidenceSuccess();
                    }
                })
        );
    }
    /**
     * 上传成交合同
     * @param map
     */
    public void uploadDealEvidence (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().uploadDealEvidence(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onUploadEvidenceSuccess();
                    }
                })
        );
    }
    /**
     * 上传图片
     */
    public void uploadPhoto (int fileType,List<MultipartBody.Part> file) {
        addSubscribe(App.getInstance().getApi().uploadFileList(fileType,file)
                .compose(RxUtil.<List<ImgBackBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<ImgBackBean>>(mView){
                    @Override
                    public void onNext(List<ImgBackBean> data) {
                        mView.onUploadFileSuccess(data);
                    }
                })
        );
    }
    /**
     *  删除图片
     * @param map
     */
    public void deletePhoto (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().deleteFile(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onDeleteFileSuccess();
                    }
                })
        );
    }
    /**
     *  获取合同类型列表
     * @param map
     */
    public void getContractTypeList (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getContractTypeList(map)
                .compose(RxUtil.<List<ContractTypeBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<ContractTypeBean>>(mView,true){
                    @Override
                    public void onNext(List<ContractTypeBean> data) {
                        mView.onGetContractTypeList(data);
                    }
                })
        );
    }
    /**
     *  获取合同类型
     * @param map
     */
    public void getContractType (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getContractType(map)
                .compose(RxUtil.<ContractTypeBean>handleResult())
                .subscribeWith(new RxSubscriber<ContractTypeBean>(mView,true){
                    @Override
                    public void onNext(ContractTypeBean data) {
                        mView.onGetContractType(data);
                    }
                })
        );
    }

}
